<?php

/*
  Action	$3

  +1 buy
  During this turn, for each card you buy which costs more than 0$, all cards count 1$ less, but not less than 0$.

 */

class Bundle extends Card implements iAction, iKingdom, iAddiction, iInfluence {

    public function __construct() {
        parent::__construct("Bundle", 3);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+1 Buy",
            "During this turn, for each card you buy which costs more than 0$, all cards count 1$ less, but not less than 0$.");
    }

    public function play(Game $game, $isRealCard) {
        $game->addBuys(1);
        ScreenDisplay::addScreenMessage($game, true, "get +1 buy", "gets +1 buy");
        $game->pushCardToInfluence($this);
        $this->influence($game);
        $game->cardActionFinished();
    }

    public function influence(Game $game) {
        $names = $game->getPlayersNames();
        $bought_cards = $game->getBoughtCards();
        $dicount = -1 * sizeof($bought_cards);

        foreach ($names as $name) {
            $cards = $game->getAllCards($name);
            foreach ($cards as $card) {
                $price = $card->getPrice($game);
                $new_price = $price->add($dicount);
                $card->setPrice($new_price);
            }
        }

        $boardCards = $game->getBoardCardsByPrice();
        foreach ($boardCards as $card) {
            $price = $card->getPrice($game);
            $new_price = $price->add($dicount);
            $card->setPrice($new_price);
        }
    }
}

?>